//
//  LineSprite.m
//  firstllk
//
//  Created by Huang Michael on 10-01-05.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//


#import "LineSprite.h"
#import "GameControl.h"

@implementation LineSprite

+ (id) LineWithinLayer:(CCLayer *)layer
{
	GameControl *ly = (GameControl *)layer;
	
	LineSprite *sprite = [LineSprite spriteWithFile:@"12star.png" rect:CGRectMake(0, 0, 5, 5)];
	[ly addChild:sprite z:10];
	
	[sprite LineSpriteInit];
	[sprite setVisible:NO];
	[sprite SetGameControl:layer];
	
	return sprite;
}

- (void)SetGameControl:(CCLayer *)layer
{
	gLayer = layer;
}

- (void) LineSpriteInit
{
	
	
	emitter = [[CCParticleSun alloc] initWithTotalParticles:12500];
	
	emitter.posVar = ccp(3, 3);
	emitter.startSize = 5;
	emitter.startSizeVar = 1;
	emitter.endSize = 5;
	emitter.endSizeVar = 1;
	ccColor4F endColor2 = {0.0f, 0.0f, 0.0f, 0.1f};
	emitter.endColor = endColor2;	
	emitter.angle = 0;
	emitter.angleVar = 0;
	emitter.life = 1;
	emitter.lifeVar = 0;
	emitter.emissionRate = 12500;
	emitter.speed = 0;
	emitter.speedVar = 1;
	// radial
	//	emitter.radialAccel = -120;
	//	emitter.radialAccelVar = 0;	
	
	[emitter stopSystem];
	
	[self addChild: emitter];
	[emitter release];
	
	
}

- (void)LineFrom:(CGPoint)ptFrom To:(CGPoint)ptTo
{
//	[self setVisible:YES];
	[self setPosition:ptFrom];
	
	id ac1 = [CCShow action];
	id ac2 = [CCMoveTo actionWithDuration:1 position:ptTo];
	id seq = [CCSequence actions:ac1, ac2, nil];
	
		emitter.position = ccp(self.contentSize.width / 2, self.contentSize.height / 2);
		[emitter resetSystem];
	
	[self runAction:seq];	
}

// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
	// in case you have something to dealloc, do it in this method
	// in this particular example nothing needs to be released.
	// cocos2d will automatically release all the children (Label)
	
	// don't forget to call "super dealloc"
	[super dealloc];
}
@end
